from flask import Flask, jsonify, current_app, make_response, send_from_directory
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate
from flask_restx import Api, Resource

import config
from blueprints.file import file_bp
from blueprints.qa import qa_bp
from blueprints.auth import auth_bp
from blueprints.role import role_bp
from blueprints.user import user_bp
from blueprints.power import power_bp
from exts import db

from models import power,user,user_role,role_power,role,article,attachment,attachment_relation
from representations.json import CustomJSONEncoder
app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)
from flask.json import JSONEncoder


migrate = Migrate(app,db)
# manager = Manager(app)
# manager.add_command('db', MigrateCommand)
@app.route('/images/<filename>/')
def get_image(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
#引入jwt模块
jwt = JWTManager()
jwt.init_app(app)


app.register_blueprint(qa_bp)
app.register_blueprint(auth_bp)
app.register_blueprint(file_bp)
app.register_blueprint(user_bp)
app.register_blueprint(role_bp)
app.register_blueprint(power_bp)

#json时间格式戳转换
app.json_encoder = CustomJSONEncoder

if __name__ == '__main__':
    app.run(debug=True)
